package com.ruoyi.project.newhope.data.mapper;

import com.ruoyi.framework.aspectj.lang.annotation.DataSource;
import com.ruoyi.framework.aspectj.lang.enums.DataSourceType;
import com.ruoyi.project.newhope.data.domain.NewHopeData;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

/**
 * 数据Mapper接口
 * 
 * @author ruoyi
 * @date 2021-02-08
 */
public interface NewHopeCollectDataMapper
{
    /**
     * 查询用户
     * 
     * @return 用户
     */
    public List<NewHopeData> selectNewHopeDataList(NewHopeData newHopeData);

    /**
     * 查询首页展示数据
     *
     * @return 用户
     */
    public List<NewHopeData> queryNewHopeDataList();

    /**
     * 查询首页展示数据
     *
     * @return 用户
     */
    public List<NewHopeData> selectNewHopeDataListByDeviceId(@Param("deviceId") Integer deviceId, @Param("limitSize") Integer limitSize);

    /**
     * 批量插入
     * @param newHopeDataList
     * @return
     */
    public Integer batchInsert(List<NewHopeData> newHopeDataList);

    /**
     * 批量插入
     * @param newHopeDataList
     * @return
     */
    @DataSource(DataSourceType.SLAVE)
    public Integer batchBackInsert(List<NewHopeData> newHopeDataList);

    /**
     * 单条插入
     * @param defaultData
     * @return
     */
    public Integer insert(NewHopeData defaultData);
    /**
     * 单条插入备份
     * @param defaultData
     * @return
     */
    public Integer insertBackup(NewHopeData defaultData);

    Integer updateInspectionCode(@Param("oldCode") String oldCode, @Param("newCode") String newCode);

    @Select("select device_id from new_hope_collect_data group by device_id")
    List<Integer> selectDataDeviceIds();

    @Select("select count(1) from (select inspection_name from new_hope_collect_data where device_id=#{deviceId} group by inspection_name) a")
    int countDeviceInspections(@Param("deviceId") Integer deviceId);

    @Update("update new_hope_collect_data set device_location=#{deviceLocation} where device_id=#{deviceId}")
    int updateDeviceLocationByDeviceId(@Param("deviceLocation") String deviceLocation, @Param("deviceId") Long deviceId);

    @Select("select * from new_hope_collect_data where create_time <= #{targetDate}")
    List<NewHopeData> selectDataByDate(@Param("targetDate") Date targetDate);

    @Delete("delete from new_hope_collect_data where create_time <= #{targetDate}")
    Integer deleteDataByDate(@Param("targetDate") Date targetDate);
}
